package com.example.riskmanage.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.riskmanage.bean.Riskgaitu;
import com.example.riskmanage.dao.RiskgaituDao;
import com.example.riskmanage.service.RiskgaituManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service
public class RiskgaituManagerImpl implements RiskgaituManager {

    @Autowired
    RiskgaituDao riskgaituDao;

    @Override
    public String getRiskgaituService(Integer uid) {
        HashMap<String, Object> map = new HashMap<>();

        //1.调用dao层接口获取数据
        List<Riskgaitu> riskgaituList = riskgaituDao.findAllByUid(uid);
        //2.将处理的数据封装到map
        map.put("riskgaituList", riskgaituList);
        map.put("flag", true);


        String respJSON = JSON.toJSONString(map);
        return respJSON;
    }

    @Override
    public String addRiskgaituService(Riskgaitu riskgaitu) {
        riskgaituDao.save(riskgaitu);
        return "ok";
    }

    @Override
    public String deleteAdminService(Integer id) {

        riskgaituDao.deleteById(id);

        return "ok";
    }

    @Override
    public String getRisklistService(Integer id) {
        Riskgaitu risk=riskgaituDao.findRiskgaituById(id);

        String respJSON = JSON.toJSONString(risk);
        return respJSON;
    }

}